<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:p="http://primefaces.org/ui" xml:lang="en" lang="en">
	<h:head />
	<body>
		<ui:composition template="/rootWeb.xhtml">
	    <ui:define name="header">
	        <title>客户管理</title>
	        <script type="text/javascript">
	        	//页面载入时注册
	        	jQuery(document).ready(function(){
	        		//鼠标移入
					jQuery("#customerTable_data tr").live("mouseover", function() {
					  	jQuery(this).css("background-color","#CCCCCC");
					  	//jQuery(this).css("background-color","#00ff00");
					});
					//鼠标移出
					jQuery("#customerTable_data tr").live("mouseout", function() {
					  	jQuery(this).css("background-color","white");
					});
				});
				function resetQueryCondition(){
					jQuery("#queryCustomerName").val("");
					jQuery("#queryCustomerCode").val("");
					jQuery("#queryCustomerRegion").val("");
					jQuery("#queryCustomerState").val("");
				}
			</script>
			<style type="text/css">
				
			</style>
		</ui:define>
	    <ui:define name="body">
	    	<h:form id="form" prependId="false">
	    		<p:outputPanel>
	    		<div style="white-space:nowrap;width: 100% "> 
						<h:panelGrid id="queryCustomer" columns="6" style="width: 100%">
							<h:outputLabel for="queryCustomerCode" value="客户编码："/>
							<p:inputText id="queryCustomerCode" value="#{customerManageAction.queryCustomer.customerCode}" />
							<h:outputLabel for="queryCustomerName" value="客户名称："/>
							<p:inputText id="queryCustomerName" value="#{customerManageAction.queryCustomer.customerName}" />
							<h:outputLabel for="queryCustomerState" value="客户状态："/>
							<h:selectOneMenu id="queryCustomerState" value="#{customerManageAction.queryCustomer.customerState}" style="width: 170px;height:25px;font-size: 17.6px">  
								<f:selectItem itemLabel="请选择" itemValue=""/>
				                <f:selectItems value="#{customerManageAction.customerStateItems}"/>
				            </h:selectOneMenu>
							<h:outputLabel for="queryCustomerRegion" value="客户地区："/>
							<p:inputText id="queryCustomerRegion" value="#{customerManageAction.queryCustomer.customerRegion}" />
				            <h:panelGrid columns="2">
								<p:commandButton value="查询" action="#{customerManageAction.doFilterCustomerList}" update=":form:customerTable"/>
								<p:commandButton value="重置" onclick="resetQueryCondition()"/>
							</h:panelGrid>
							<h:panelGrid columns="2">
								<p:commandButton value="新增" action="#{customerManageAction.setAddCustomer}" update=":form:addCustomerDlgID" oncomplete="addCustomerDlg.show()"/>
								<p:commandButton value="导入导出"/>
							</h:panelGrid>
						</h:panelGrid>
				</div>
				<p/>
				</p:outputPanel>
				<p:dataTable id="customerTable" value="#{customerManageAction.customerList}" var="customer" rowKey="#{customerList}" emptyMessage="没有记录！"
	    				paginator="true" rows="10"  	rowsPerPageTemplate="5,10,15"	paginatorAlwaysVisible="false" 	paginatorPosition="bottom" currentPageReportTemplate="{currentPage} / {totalPages}"
               			paginatorTemplate="{CurrentPageReport}  {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"   >
               			<f:facet name="header">客户列表</f:facet>
               			<p:column headerText="客户编码">#{customer.customerCode}</p:column>
               			<p:column headerText="客户名称">#{customer.customerName}</p:column>
               			<p:column headerText="客户状态">
               				<h:selectOneMenu value="#{customer.customerState}" disabled="true" >  
				                <f:selectItems value="#{customerManageAction.customerStateItems}"/>
				            </h:selectOneMenu>
               			</p:column>
               			<p:column headerText="客户地区">#{customer.customerRegion}</p:column>
               			<p:column headerText="座机">#{customer.customerLandlinePhone}</p:column>
               			<p:column headerText="手机">#{customer.customerCellphone}</p:column>
               			<p:column headerText="累积下单量" style="text-align:right">#{customer.totalOrderWeight}</p:column>
               			<p:column headerText="最近下单日期" style="text-align:right">#{customer.lastOrderDate}</p:column>
               			<p:column headerText="最近下单量" style="text-align:right">#{customer.lastOrderWeight}</p:column>
               			<p:column headerText="操作">
			    			<p:commandLink value="查看"  action="#{customerManageAction.setViewCustomer(customer)}" update=":form:viewCustomerDlgID"
			    				oncomplete="viewCustomerDlg.show()"	style="margin-right:5px;color:RED"/>
			    			<p:commandLink value="修改"  action="#{customerManageAction.setUpdateCustomer(customer)}" update=":form:updateCustomerDlgID"
			    				oncomplete="updateCustomerDlg.show()"	style="margin-right:5px;color:RED"/>
			    			<p:commandLink value="删除"  action="#{customerManageAction.setUpdateCustomer(customer)}" update=":form:updateCustomerDlgID"
			    				oncomplete="deleteCustomerDlg.show()"	style="margin-right:5px;color:RED"/>
			    			<p:commandLink value="所属模具" action="#{customerManageAction.queryCustomerMold(customer)}" update=":form:viewCustomerDlgID,:form:customerMoldDlgID"
			    				oncomplete="customerMoldDlg.show()" style="margin-right:5px;color:RED"/>
			    		</p:column>
               	</p:dataTable> 
               	<ui:include src="addAndUpdateCustomer.xhtml"></ui:include>
               	<!-- 客户模具列表 -->
               	<p:dialog id="customerMoldDlgID" header="客户模具列表" widgetVar="customerMoldDlg" modal="true" resizable="false" >
               		<p:outputPanel >
               			<h:panelGrid columns="4">
	               			<h:outputText  value="客户编码："/>
	               			<h:outputText  value="#{customerManageAction.viewCustomer.customerCode}" styleClass="outputInfoFont" style="color:RED"/>
	               			<h:outputText  value="客户姓名："/>
	               			<h:outputText  value="#{customerManageAction.viewCustomer.customerName}" styleClass="outputInfoFont" style="color:RED"/>	
               			</h:panelGrid>
               			<p/>
               			<p:dataTable id="customerMoldTable" value="#{customerManageAction.customerMoldList}" var="customerMold" rowKey="#{customerMold}" emptyMessage="没有记录！"
		    				paginator="true" rows="10"  	rowsPerPageTemplate="5,10,15"	paginatorAlwaysVisible="false" 	paginatorPosition="bottom" currentPageReportTemplate="{currentPage} / {totalPages}"
	               			paginatorTemplate="{CurrentPageReport}  {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"   >
	               				<f:facet name="header">客户模具列表</f:facet>
	               				<p:column headerText="模具型号">#{customerMold.mold.moldNumber}</p:column>
	               				<p:column headerText="模具系列">#{customerMold.mold.moldSeries.seriesName}</p:column>
	               				<p:column headerText="模具品名">#{customerMold.mold.moldName}</p:column>
	               				<p:column headerText="累积下单量">#{customerMold.totalOrderWeight}</p:column>
	               				<p:calendar id="queryCustomerMoldLastDate" value="#{customerMold.lastOrderDate}" size="15"
		    					timeZone="GMT+8" pattern="yyyy-MM-dd" showButtonPanel="true" navigator="true"/>
	               				<p:column headerText="最近下单量">#{customerMold.lastOrderWeight}</p:column>
	               				<p:column headerText="操作">
	               						<p:commandLink value="删除" style="margin-right:5px;color:RED" action="#{customerManageAction.setDeleteCustomerMold(customerMold)}"
	               							oncomplete="deleteCustomerMoldDlg.show()"/>
								</p:column>
               			</p:dataTable>
               		</p:outputPanel>
               		<f:facet name="footer">
						<p:commandButton value="添加" action="#{customerManageAction.findAllChoiceMold}"
								update=":form:moldListDlgID" oncomplete="moldListDlg.show()"/>
						<p:spacer width="5"/>
						<p:commandButton value="退出" onclick="customerMoldDlg.hide()"/>
					</f:facet>
               	</p:dialog>
               	<!-- 删除客户模具-->
				<p:confirmDialog id="deleteCustomerMoldDlgID" message="确认删除客户模具吗?"
					header="删除客户模具" severity="alert" widgetVar="deleteCustomerMoldDlg">
					<p:commandButton value="确定" update=":form:customerMoldDlgID,:form:customerMoldTable" action="#{customerManageAction.deleteCustomerMold}"
						oncomplete="if(this.args.error){alert(this.args.error)}else{alert(this.args.msg);deleteCustomerMoldDlg.hide();customerMoldDlg.show()}"  />
					<p:commandButton value="取消" onclick="deleteCustomerMoldDlg.hide()" type="button" />
				</p:confirmDialog>
               	<!-- 选择模具列表 -->
               	<p:dialog id="moldListDlgID" header="选择模具列表" widgetVar="moldListDlg" modal="true" resizable="false" >
               		 <div style="white-space:nowrap;width:100%">
	    	            <h:panelGrid id="queryGrid" columns="4">
		    		        <h:outputLabel for="queryMoldName" value="模具名称："/>
		    				<h:selectOneMenu id="queryMoldName" value="#{customerManageAction.queryMold.moldName}" style="width: 120px">  
		    				 	<f:selectItem itemLabel="请选择"  itemValue=""/>
				                <f:selectItems value="#{customerManageAction.moldNameItems}"/>
				            </h:selectOneMenu>
							<h:outputLabel for="queryMoldNumber" value="模具型号："/>
		    				<p:inputText id="queryMoldNumber" value="#{customerManageAction.queryMold.moldNumber}" size="15" style="width: 120px"/>
		    		        <h:outputLabel for="querySeriesName" value="模具系列："/>
		    		        <p:inputText id="querySeriesName" value="#{customerManageAction.querySeries.seriesName}" style="width: 110px" />
		    		        <p:commandButton  value="选择" action="#{customerManageAction.findAllSeries}" oncomplete="selectSeriesDlg.show();" update=":form:querySeriesTable"/>
		    		        <h:panelGrid  columns="2">
		    		            <p:commandButton value="查询" action="#{customerManageAction.findAllChoiceMold}" update=":form:selectedMoldTable"  icon="ui-icon-search"/>
		    		            <p:commandButton value="重置" onclick="resetQueryCondition();"/>
		    		        </h:panelGrid>  
		    	        </h:panelGrid> <p/>
		    	    </div>
               		<p:outputPanel >
               			<p:dataTable id="selectedMoldTable" value="#{customerManageAction.queryMoldList}" var="mold" rowKey="#{mold}" 
               				emptyMessage="没有记录！" selection="#{customerManageAction.selectedMoldList}"
		    				paginator="true" rows="10"  	rowsPerPageTemplate="5,10,15"	paginatorAlwaysVisible="false" 	paginatorPosition="bottom" currentPageReportTemplate="{currentPage} / {totalPages}"
	               			paginatorTemplate="{CurrentPageReport}  {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"   >
	               				<f:facet name="header">模具列表</f:facet>
	               				<p:column selectionMode="multiple"></p:column>
	               				<p:column headerText="模具系列">#{mold.moldSeries.seriesName}</p:column>
	               				<p:column headerText="模具品名">#{mold.moldName}</p:column>
	               				<p:column headerText="模具型号">#{mold.moldNumber}</p:column>
               			</p:dataTable>
               		</p:outputPanel>
               		<f:facet name="footer">
						<p:commandButton value="添加" action="#{customerManageAction.saveCustomerMold}" update=":form:customerMoldDlgID"
							oncomplete="if(this.args.error){alert(this.args.error)}else{alert(this.args.msg);moldListDlg.hide();customerMoldDlg.show()}" />
						<p:spacer width="5"/>
						<p:commandButton value="取消" onclick="moldListDlg.hide()"/>
					</f:facet>
               	</p:dialog>
               	<p:dialog id="selectseriesDlgID" header="选择模具系列" widgetVar="selectSeriesDlg" modal="true"  resizable="false">
		            <h:panelGrid  columns="2" cellpadding="5">
			        <p:dataTable id="querySeriesTable" value="#{customerManageAction.querySeriesList}" var="moldSeries" rowKey="#{moldSeries}" emptyMessage="没有记录！"
					           selection="#{customerManageAction.selectedSeries}"
				               paginator="true" rows="10"  	rowsPerPageTemplate="5,10,15"	paginatorAlwaysVisible="true" 	paginatorPosition="bottom" currentPageReportTemplate="{currentPage} / {totalPages}"
		                       paginatorTemplate="{CurrentPageReport}  {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"  >
		               <p:column selectionMode="single" ></p:column>
			           <p:column headerText="系列名称">#{moldSeries.seriesName}</p:column>
			           <p:column headerText="系列代码">#{moldSeries.seriesCode}</p:column>
			           <p:column headerText="系列描述">#{moldSeries.seriesRemark}</p:column>
			        </p:dataTable>
			        <f:facet name="footer">
			           <p:commandButton value="确定"  action="#{customerManageAction.setQuerySeries}"
			           oncomplete="selectSeriesDlg.hide()" update=":form:querySeriesName"/>
			        </f:facet>
		            </h:panelGrid>
	            </p:dialog>
			</h:form>
	    </ui:define>
		</ui:composition>
	</body>
</html>
